package ua.kharkov.knure.mikhaylov.st4.web.command;

import java.util.Map;
import java.util.TreeMap;

import org.apache.log4j.Logger;

/**
 * Holder for all commands.
 * 
 * @author Saint
 */
public class CommandContainer {

	private static final Logger log = Logger.getLogger(CommandContainer.class);

	private static Map<String, Command> commands = new TreeMap<String, Command>();

	static {
		// common commands
		commands.put("noCommand", new NoCommand());
		commands.put("logout", new LogoutCommand());

		// out of control commands
		commands.put("login", new LoginCommand());
		commands.put("registration", new BrowseRegistrationCommand());
		commands.put("register", new RegisterCommand());

		// client commands
		// commands.put("listMenu", new ListMenuCommand());
		commands.put("updateSettings", new UpdateSettingsCommand());
		commands.put("browseAccounts", new BrowseAccountsCommand());
		commands.put("browseAccountCreation",
				new BrowseAccountCreationCommand());
		commands.put("createAccount", new CreateAccountCommand());
		commands.put("viewAccount", new ViewAccountCommand());
		commands.put("createCard", new CreateCardCommand());
		commands.put("deleteCard", new DeleteCardCommand());
		commands.put("blockAccount", new BlockAccountCommand());
		commands.put("browseUserPage", new BrowseUserPageCommand());
		commands.put("refillAccount", new RefillAccountCommand());
		commands.put("browseRefillPage", new BrowseRefillPageCommand());
		commands.put("browseCreatePaymentPage",
				new BrowseCreatePaymentPageCommand());
		commands.put("createPayment", new CreatePaymentCommand());
		commands.put("continuePaymentCreation",
				new ContinueCreatePaymentCommand());
		commands.put("viewPayments", new ViewPaymentsCommand());
		commands.put("rejectPayment", new RejectPaymentCommand());
		commands.put("approovePayment", new ApproovePaymentCommand());
		commands.put("viewSettings", new ViewSettingsCommand());

		// admin commands
		commands.put("unblockAccount", new UnblockAccountCommand());
		commands.put("browseBlockedAccounts",
				new BrowseBlockedAccountsCommand());
		commands.put("browseAdminPage", new BrowseAdminPageCommand());

		log.debug("Command container was successfully initialized");
		log.trace("Number of commands --> " + commands.size());
	}

	/**
	 * Returns command object with the given name.
	 * 
	 * @param commandName
	 *            Name of the command.
	 * @return Command object.
	 */
	public static Command get(String commandName) {
		if (commandName == null || !commands.containsKey(commandName)) {
			log.trace("Command not found, name --> " + commandName);
			return commands.get("noCommand");
		}

		return commands.get(commandName);
	}

}